<!DOCTYPE html>
<head>
    <title>新增修改用户</title>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/jquery.hammer/hammer.min.js"></script>
    <script src="/js/jquery.extend.js" type="text/javascript"></script>
    <script src="/js/jquery.scrolltopcontrol/scrolltopcontrol.js"></script>
    <script src="/js/jquery-form.js" type="text/javascript"></script>
    <script src="/js/dialog.js"></script>
    <script src="/js/comm.js" type="text/javascript"></script>

    <link href="/css/bootstrap/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="/css/font-awesome.css" rel="stylesheet" />
    <link href="/css/bootstrap.table/bootstrap-table.min.css" rel="stylesheet" type="text/css"/>
    <link href="/css/dialog.css" rel="stylesheet" />
    <link href="/css/common.css" rel="stylesheet" type="text/css"/>
</head>
<body style="padding: 0px 6px 0px 6px;overflow-x: hidden;overflow-y: scroll">
    <div class="addEdit-title" >
        <h4>新增用户</h4>
    </div>
    <div style="width: 100%;margin-top: 10px;">
        <form class="form-horizontal" id="articleForm" role="form">
            <div class="form-group">
                <label class="col-sm-2 control-label">客户名称<span style="color: red;">*</span></label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" style="width: 80%" id="clientName" name="clientName"  placeholder="请输入客户名">
                    <span class="help-block" style="color: red; display: none;">请输入客户名</span>
                </div>
                <label class="col-sm-2 control-label">客户电话</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" style="width: 80%" id="clientPhone" name="clientPhone"  placeholder="请输入客户电话">
                    <span class="help-block" style="color: red; display: none;">请输入客户电话</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">客户编号<span style="color: red;">*</span></label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" style="width: 80%" id="clientCode" name="clientCode"  placeholder="请输入客户编号">
                    <span class="help-block" style="color: red; display: none;">请输入客户编号</span>
                </div>
                <label class="col-sm-2 control-label">记录本</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" style="width: 80%" id="recordBook" name="recordBook"  placeholder="请输入记录本编号">
                    <span class="help-block" style="color: red; display: none;">请输入记录本编号</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">客户邮箱</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" style="width: 80%" id="clientEmail" name="clientEmail"  placeholder="请输入客户邮箱">
                    <span class="help-block" style="color: red; display: none;">请输入客户邮箱</span>
                </div>
                <label class="col-sm-2 control-label">客户身份证号</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" style="width: 80%" id="clientCard" name="clientCard"  placeholder="请输入身份证号">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">客户地址</label>
                <div class="col-sm-7">
                    <input type="text" class="form-control"  id="clientAddress" name="clientAddress"  placeholder="请输入客户地址" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">客户性别<span style="color: red;">*</span></label>
                <div class="col-sm-7">
                    <select class="form-control" id="clientSex" name="clientSex" style="width: 20%">
                        <option value="1" >男</option>
                        <option value="2" >女</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">是否启用<span style="color: red;">*</span></label>
                <div class="col-sm-7">
                    <select class="form-control" id="isUse" name="isUse" style="width: 20%">
                        <option value="1" >是</option>
                        <option value="2" >否</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">备注</label>
                <div class="col-sm-7">
                    <textarea class="form-control"  id="clientRemark" name="clientRemark"  ></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-12 control-label" style="text-align: center;">
                    <button type="button" class="btn btn-default" onclick="cancelArticle(this)">取消</button>
                    <button type="button" class="btn btn-primary" onclick="saveArticle(this);">确定</button>
                </label>
            </div>
        </form>
    </div>
    <a href="#top" id="goTop"><i class="fa fa-angle-up fa-3x"></i></a>
</body>
<script type="text/javascript">
    var idarticle = "";
    $(function () {
        initInput();
        //判断是修改还是新增
        idarticle = getQueryString("clientid");
        if(idarticle!=null&&idarticle!=""){
            $(".addEdit-title").html("<h4>修改客户信息</h4>");
            getArticle(idarticle);
        }

    })

    function saveArticle(e){

        var b = saveCheckInfo();
        if(!b){
            return false;
        }
        $(e).attr("disabled","disabled");
        var data ={};
        data["clientName"] = $("#clientName").val();
        data["clientPhone"] = $("#clientPhone").val();
        data["clientCode"] = $("#clientCode").val();
        data["recordBook"] = $("#recordBook").val();
        data["clientEmail"] = $("#clientEmail").val();
        data["clientCard"] = $("#clientCard").val();
        data["clientAddress"] = $("#clientAddress").val();
        data["clientSex"] = $("#clientSex").val();
        data["isUse"] = $("#isUse").val();
        data["clientRemark"] = $("#clientRemark").val();
        data["clientId"] = idarticle;
        if(idarticle==null||idarticle==""){//保存
            $.post("/client/saveClientInfo.do",data,function (datas) {
                if(datas.type){
                    okDail('保存成功!',"client_list.html?btnPurid="+btnPurid);
                }else {
                    errorDail('保存失败!');
                    $(e).removeAttr("disabled");
                }
            },"json")
        }else {//修改
            data["id"] = idarticle;
            $.post("/client/updateClientInfo.do",data,function (datas) {
                if(datas.type){
                    okDail('修改成功!', "client_list.html?btnPurid="+btnPurid);
                }else {
                    errorDail('修改失败!');
                    $(e).removeAttr("disabled");
                }
            },"json")
        }

    }

    //失去焦点判断是否为空
    function initInput() {
        $("#clientName").blur(function(){  // 失去焦点
            var info = $(this).val();
            if(info!=null&&info!=""){
                $(this).next().hide();
            }else {
                $(this).next().show();
            }

        });

        $("#clientCode").blur(function(){  // 失去焦点
            var info = $(this).val();
            if(info!=null&&info!=""){
                $(this).next().hide();
            }else {
                $(this).next().show();
            }

        });

        $("#recordBook").blur(function(){  // 失去焦点
            var info = $(this).val();
            if(info!=null&&info!=""){
                $(this).next().hide();
            }else {
                $(this).next().show();
            }

        });
    }

    //判断是否为空
    function saveCheckInfo(){
        var b = true;
        var title = $("#clientName").val();
        if(title!=null&&title!=""){
            $("#clientName").next().hide();
        }else {
            $("#clientName").next().show();
            b = false;
        }

        var clientCode = $("#clientCode").val();
        if(clientCode!=null&&clientCode!=""){
            $("#clientCode").next().hide();
        }else {
            $("#clientCode").next().show();
            b = false;
        }

        var recordBook = $("#recordBook").val();
        if(recordBook!=null&&recordBook!=""){
            $("#recordBook").next().hide();
        }else {
            $("#recordBook").next().show();
            b = false;
        }

        return b;
    }
    
    function getArticle(idarticle) {
        $.post("/client/getClientInfo.do",{"clientid":idarticle},function (data) {
            if(data.type){
                var  message = data.info;
                $("#clientName").val(message.clientName);
                $("#clientPhone").val(message.clientPhone);
                $("#clientCode").val(message.clientCode);
                $("#recordBook").val(message.recordBook);
                $("#clientEmail").val(message.clientEmail);
                $("#clientCard").val(message.clientCard);
                $("#clientAddress").val(message.clientAddress);
                $("#clientSex").val(message.clientSex);
                $("#isUse").val(message.isUse);
                $("#clientRemark").val(message.clientRemark);
            }else{
                errorDail('获取信息失败!');
            }
        },"json")
    }
    
    function cancelArticle() {
        window.location.href="/jymf/client_list.html?btnPurid="+btnPurid;
    }
</script>
</html>